package cn.iocoder.yudao.module.yyzx.service.nurse_level_content;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_level_content.vo.*;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.nurse_level_content.NurseLevelContentDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.yyzx.dal.mysql.nurse_level_content.NurseLevelContentMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.yyzx.enums.ErrorCodeConstants.*;

/**
 * 护理级别对应的护理内容 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class NurseLevelContentServiceImpl implements NurseLevelContentService {

    @Resource
    private NurseLevelContentMapper nurseLevelContentMapper;

    @Override
    public Integer createNurseLevelContent(NurseLevelContentSaveReqVO createReqVO) {
        // 插入
        NurseLevelContentDO nurseLevelContent = BeanUtils.toBean(createReqVO, NurseLevelContentDO.class);
        nurseLevelContentMapper.insert(nurseLevelContent);
        // 返回
        return nurseLevelContent.getId();
    }

    @Override
    public void updateNurseLevelContent(NurseLevelContentSaveReqVO updateReqVO) {
        // 校验存在
        validateNurseLevelContentExists(updateReqVO.getId());
        // 更新
        NurseLevelContentDO updateObj = BeanUtils.toBean(updateReqVO, NurseLevelContentDO.class);
        nurseLevelContentMapper.updateById(updateObj);
    }

    @Override
    public void deleteNurseLevelContent(Integer id) {
        // 校验存在
        validateNurseLevelContentExists(id);
        // 删除
        nurseLevelContentMapper.deleteById(id);
    }

    private void validateNurseLevelContentExists(Integer id) {
        if (nurseLevelContentMapper.selectById(id) == null) {
            throw exception(NURSE_LEVEL_CONTENT_NOT_EXISTS);
        }
    }

    @Override
    public NurseLevelContentDO getNurseLevelContent(Integer id) {
        return nurseLevelContentMapper.selectById(id);
    }

    @Override
    public PageResult<NurseLevelContentDO> getNurseLevelContentPage(NurseLevelContentPageReqVO pageReqVO) {
        return nurseLevelContentMapper.selectPage(pageReqVO);
    }

}